//
//  YongHuData.m
//  Class
//
//  Created by 钟纪旺 on 17/3/15.
//  Copyright © 2017年 zjw. All rights reserved.
//

#import "YongHuData.h"
#import "NetWorkingHandle.h"
#import "MJExtension.h"
#import "CustomModel.h"
@interface YongHuData ()
@property (strong, nonatomic) CustomModel *model;

@property (strong, nonatomic) UserModel *userMode;
@end

@implementation YongHuData

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [NetWorkingHandle requestDataWithURL:@"/users/list" withParams:@{} withRequestType:GET succeccBlock:^(NSDictionary *dic) {
        if ([dic[@"errcode"] intValue] == 0) {
            _userMode = [UserModel mj_objectWithKeyValues:dic];
            
            NSLog(@"%@",_userMode.errmsg);
            NSLog(@"%ld",(long)_userMode.errcode);
            
            
            for (NSDictionary * dic in _userMode.record.deps) {
                NSLog(@"deps--------%@------%@-------\n",dic[@"id"],dic[@"name"]);
            }
            
            
            //
            for (NSDictionary * dic in _userMode.record.data) {
                NSLog(@"data--------%@------%@-------%@----------\n",dic[@"id"],dic[@"name"],dic[@"department"]);
            }
            dispatch_sync(dispatch_get_main_queue(), ^{
                [self.tableView reloadData];
            });
        }
        
    } failedBlock:^(NSError *error) {
        
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(!_userMode){
        return 0;
    }
    return _userMode.record.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"my" forIndexPath:indexPath];
    cell.textLabel.text =_userMode.record.data[indexPath.row][@"name"];
    cell.detailTextLabel.text =_userMode.record.data[indexPath.row][@"department"];
    
    return cell;






}
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewRowAction *no1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        //[data removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
        /*风格*/
    }];
    
    UITableViewRowAction *no2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        
    }];
    no2.backgroundColor = [UIColor blueColor];
    
    return @[no1,no2];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
